package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.dto.R;
import com.qf.pojo.SysCategory;
import com.qf.service.SysCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * created by 赵文韬 on 2022/3/20 9:50
 */
@RestController
public class SysCategoryController {
    private SysCategoryService sysCategoryService;
    @Autowired
    public void setSysCategoryService(SysCategoryService sysCategoryService) {
        this.sysCategoryService = sysCategoryService;
    }

    @GetMapping("findById/{id}")
    public SysCategory findById(@PathVariable Long id){
        SysCategory byId = sysCategoryService.findById(id);
        return byId;
    }
    @PostMapping("add")
    public R add(@RequestBody SysCategory sysCategory){
        sysCategoryService.addSysCategory(sysCategory);
        return R.setOk();
    }
   /* @GetMapping("find/{categoryName}")
    public PageInfo<SysCategory> findPage(@RequestParam(defaultValue = "1") int pageNum , @RequestParam(defaultValue = "1") int pageSize , @PathVariable String categoryName){
        *//*PageInfo<SysCategory> sysCategoryPageInfo = sysCategoryService.fingByPage(pageNum, pageSize, categoryName);
        return sysCategoryPageInfo;*//*
    }*/
    @GetMapping("find")
    public R findAllByPage(@RequestParam(defaultValue = "2") int pageNum,@RequestParam(defaultValue = "2") int pageSize,String categoryName){
        PageInfo<SysCategory> sysCategoryPageInfo = sysCategoryService.findByPage(pageNum, pageSize, categoryName);
        return R.setOk(sysCategoryPageInfo);
    }
    @PostMapping("update")
    public R update(@RequestBody SysCategory sysCategory){
        int i = sysCategoryService.sysCategoryUpdate(sysCategory);
        /*if (i>0){
            return R.setOk();
        }else return R.setError();*/
        return R.setOk();
    }
    @PostMapping("delete")
    public R delete(@RequestBody List<Long> ids){
        int re = sysCategoryService.deleteById(ids);
        return R.setOk(re);
    }

}
